//
//  AllCommentTableViewCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/8/5.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "AllCommentTableViewCell.h"

@interface AllCommentTableViewCell ()

@property (nonatomic, strong) UIButton *commentBtn;
@property (nonatomic, strong) UIButton *praiseBtn;

@property (nonatomic, strong) UIImageView *headView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *commentLabel;

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *cheadView;
@property (nonatomic, strong) UILabel *cnameLabel;
@property (nonatomic, strong) UILabel *ccommentLabel;

@end

@implementation AllCommentTableViewCell

+ (AllCommentTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"AllCommentTableViewCell";
    AllCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[AllCommentTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(10), ScreenX375(29), ScreenX375(29))];
    self.headView.clipsToBounds = YES;
    self.headView.layer.cornerRadius = ScreenX375(14.5);
    [self addSubview:self.headView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(50), ScreenX375(15), ScreenX375(150), ScreenX375(18))];
    self.nameLabel.textColor = FONTCOLOR_BLACK;
    self.nameLabel.font = Kfont(14);
    [self addSubview:self.nameLabel];
    
    self.commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(48), ScreenX375(42), ScreenX375(200), ScreenX375(16))];
    self.commentLabel.textColor = FONTCOLOR_BLACK;
    self.commentLabel.font = Kfont(14);
    self.commentLabel.numberOfLines = 0;
    [self addSubview:self.commentLabel];
    
    self.commentBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(94), ScreenX375(15), ScreenX375(30), ScreenX375(18))];
    [self.commentBtn setTitle:@"回复" forState:UIControlStateNormal];
    [self.commentBtn setTitleColor:REXADECIMALCOLOR(@"#666666") forState:UIControlStateNormal];
    self.commentBtn.titleLabel.font = Kfont(14);
    [self.commentBtn addTarget:self action:@selector(commentAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.commentBtn];
    
    self.praiseBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(66), ScreenX375(15), ScreenX375(50), ScreenX375(18))];
    [self.praiseBtn setTitle:@"16" forState:UIControlStateNormal];
    [self.praiseBtn setTitleColor:REXADECIMALCOLOR(@"#666666") forState:UIControlStateNormal];
    self.praiseBtn.titleLabel.font = Kfont(13);
    [self.praiseBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
    self.praiseBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [self.praiseBtn addTarget:self action:@selector(appraiseAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.praiseBtn];
}

- (void)setCommentModel:(CommentModel *)commentModel {
    _commentModel = commentModel;
    if ([commentModel.userPic class] != [NSNull class]) {
        [self.headView sd_setImageWithURL:[NSURL URLWithString:commentModel.userPic] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    self.nameLabel.text = commentModel.userName;
    self.commentLabel.text = commentModel.content;
    [self.praiseBtn setTitle:[NSString stringWithFormat:@"  %@",_commentModel.zanNum] forState:UIControlStateNormal];
    if ([_commentModel.zanNum integerValue]) {
        [self.praiseBtn setImage:ImageWithName(@"已点赞") forState:UIControlStateNormal];
    }else {
        [self.praiseBtn setImage:ImageWithName(@"点赞") forState:UIControlStateNormal];
    }
    CGFloat height = kGetStringHeight(commentModel.content, CGSizeMake(SCREEN_WIDTH - ScreenX375(64), MAXFLOAT), Kfont(14));
    self.commentLabel.frame = CGRectMake(ScreenX375(48), ScreenX375(42), SCREEN_WIDTH - ScreenX375(64), height + ScreenX375(2));
}

- (void)commentAction {
    if (_commentClick) {
        _commentClick();
    }
}

- (void)appraiseAction {
    if (_appraiseClick) {
        _appraiseClick();
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
